var Balance = (function($) {
	var idModel = {
		name : 'user_id',
		index : 'user_id',
		width : 60,
		sorttype : "int",
		hidden:true,
	};
	var userNameModel = {
			name : 'username',
			index : 'username',
			width : 60,
			sorttype : "string"
		};
	var balanceModel = {
		name : 'balance',
		index : 'balance',
		width : 80,
		align : "right",
		sorttype : "float",
		formatter : 'currency'
	};

	return {
		initBalanceEvent : function() {
			$("#submit").click(function() {
				Balance.bindBalance();
				return false;
			});
		},
		initBalance : function() {
			Balance.initBalanceEvent();
		},

		bindBalance : function() {

			var gridOption = $.extend(Report.gridOption, {
				height : 500,
				colNames : [ 'User Id', 'User', 'Balance' ],
				colModel : [ idModel, userNameModel, balanceModel ]
			});

			$.blockUI();
			$.ajax( {
				type : "POST",
				url : "index.php/admin/report/balanceData",
				dataType : "json",
				data : {
					userType : $("#user-type").val()
				},
				success : function(response) {
					// Show the grid
					gridOption.data = response.Main;
					gridOption.userData = response.Total;

					$("#jqgrid-table").jqGrid('GridUnload');
					$("#jqgrid-table").jqGrid(gridOption);
					Report.initColumnChooser();

				},
				complete : function() {
					$.unblockUI()
				}
			});
		}
	};
})(jQuery);
